package gui;

import java.util.Locale;

import org.apache.pivot.beans.BXMLSerializer;
import org.apache.pivot.collections.Map;
import org.apache.pivot.util.Resources;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Window;

public class Main extends Application.Adapter {
	private Window mainWindow = null;

    public static final String LANGUAGE_KEY = "language";

    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception {
        String language = properties.get(LANGUAGE_KEY);
        Locale locale = (language == null) ? Locale.getDefault() : new Locale(language);
        Resources resources = new Resources(MainWindow.class.getName(), locale);

        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        mainWindow = (MainWindow) bxmlSerializer.readObject(getClass().getResource("main_window.bxml"), resources);
        mainWindow.open(display);
    }

    @Override
    public boolean shutdown(boolean optional) {
        if (mainWindow != null) {
            mainWindow.close();
        }

        return false;
    }

    public static void main(String[] args) {
        DesktopApplicationContext.main(Main.class, args);
    }
}
